<template>
  <BasicModal :show="show" title="放弃" width="30%" :widthComfirm="true" @comfirm="comfirm" @closeModal="show = false">
    <template #content>
      <a-form ref="formRef" :model="form" :rules="rules" :label-col="{ style: { width: '100px', textAlign: 'right' } }">
        <a-form-item label="放弃原因" name="reason">
          <a-textarea v-model:value="form.reason" showCount :maxlength="1000"  />
        </a-form-item>
      </a-form>
    </template>
  </BasicModal>
</template>

<script setup lang='ts'>
import { ref } from "vue"
import type { Rule } from 'ant-design-vue/es/form';
import BasicModal from "./BasicModal.vue";
import {
  interview, interviewSchedule, arriveSchedule, trainingSchedule,
  trainingArrive, agreementSigned, contractSigned, onBoardingProgress,
  secondInterview
} from "@/api/application-details/index.ts";

import { comStores } from '@/store/common/comStore';
import { message } from "ant-design-vue";
const store = comStores()


const show = ref<boolean>(false);
const form = ref({
  reason: ""
})
const rules: Record<string, Rule[]> = {
  reason: [{ required: true, message: '请填写原因', trigger: 'change' }],
};
const formRef = ref<any>(null)
const comfirm = async () => {
  const res = await formRef.value.validate();
  if (!res) return;
  const { resumeId, processId, processSort } = store.currentResume;
  console.log(processSort, 'processSort')
  const { userName } = store.userInFor
  let param: any = {
    resumeId: resumeId,
    processId: processId,
    result: "放弃",
    operator: userName,
    reason: form.value.reason,
  }
  let data: any = {}
  if (processSort == '5') {  //待约面-约面
    data = await interviewSchedule(param)
  } else if (processSort == '8') {  //待面试
    data = await interview(param)
  } else if (processSort == '11') {
    param.assess = param.remark
    data = await arriveSchedule(param)
  } else if (processSort == '15' ) {
    data = await trainingSchedule(param)
  } else if (processSort == '20'  ) {
    data = await trainingArrive(param)
  } else if (processSort == '33') {
    data = await agreementSigned(param)
  } else if (processSort == '36') {
    data = await contractSigned(param)
  } else if (processSort == '43') {
    param.abandonReason = form.value.reason;
    delete param.remark
    data = await onBoardingProgress(param)
  } else if (processSort == 39) {
    param.editStatus = 'ABANDON'
    data = await secondInterview(param)
  }
  console.log(data, 'data')
  if (data && data.code === '10000') {
    message.success("操作成功")
    show.value = false;
    form.value.reason = "";
    await store.getResumeInfo(resumeId)
  } else {
    message.error(data.msg)
  }
  // formRef.value.resetFields();
}
defineExpose({ show })
</script>

<style lang="less" scoped>
.progress {
  display: flex;
  justify-content: end;
  margin: 24px 0;
  padding-top: 24px;
  ;
  font-weight: 400;
  font-size: 14px;
  color: #333333;

  .desc {
    font-weight: 400;
    font-size: 14px;
    color: #209EE4;
  }
}
</style>